<#--POJO-->
<#-- 传入参数 Func func, DataTable table --> 
package ${func.javaPkg}.pojo;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Map;
import java.math.BigDecimal;
import com.vecspace.data.model.RowMapper;
import com.vecspace.data.model.IdEntity;
import com.vecspace.dicttable.DictAll;
import org.hibernate.annotations.Polymorphism;
import org.hibernate.annotations.PolymorphismType;
import com.fasterxml.jackson.annotation.JsonIgnore;
import javax.persistence.Table;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Transient;
<#if table.useRowLock!false == true>
import com.vecspace.data.model.IDataLockState;
</#if>

<#if table.hasQMoneyYuanType == true >
import com.sinoccdc.data.numerical.QMoneyYuan;
</#if>
<#if table.hasQMoneyWanYuanType == true >
import com.sinoccdc.data.numerical.QMoneyWanYuan;
</#if>
<#if table.hasQNumberType == true >
import com.sinoccdc.data.numerical.QNumber;
</#if>
<#if table.hasQNumberType == true >
import com.sinoccdc.data.numerical.QPercent;
</#if>

/** ${table.tableCaption!''}
 * @template dayu-code-builder
 * @author ${author}
 * @reviewer 
 * @createTime ${nowTime}
 * @version 1.0
 */
@Entity
@Polymorphism(type = PolymorphismType.EXPLICIT)
@Table(name = "${table.tableName}")
public class ${table.className} implements IdEntity, <#if table.useRowLock!false == true>IDataLockState, </#if>java.io.Serializable {

    public ${table.className}(){
    }
    
    private static final long serialVersionUID = 100${table.id?c}L;

<#list columns as column>
    /** ${column.columnCaption!''} */
    private ${column.javaType} ${column.varName};
</#list>
<#list columns as column>
<#if (column.codeType!'')?length gt 0>

    /**${column.columnCaption!''} 字典码*/
    public static final String ${column.propName}Code = "${column.codeType}";
    /**${column.columnCaption!''}*/
    @Transient
    @Column(name = "${column.columnName?upper_case}")
    public String get${column.propName}Caption(){
        return DictAll.getCachedItemName(${column.propName}Code, ${column.varName});
    }
</#if>
</#list>

    <#if table.idVarName != 'id'>
    @Override
    public Long getId(){
        return table.idColumn.varName;
    }
    </#if>

/****************************** getter setter *******************************************/

<#list columns as column>

    /**${column.columnCaption!''}*/
    <#if column.jsonIgnore == true>
    @JsonIgnore(true)
    </#if>
    <#if column.varName == table.idVarName>
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    </#if>
    @Column(name = "${column.columnName?upper_case}")<#if column.javaType=="Boolean"><#if column.javaType !='String'>@org.hibernate.annotations.Type(type="org.hibernate.type.NumericBooleanType")<#else>@org.hibernate.annotations.Type(type="yes_no")</#if></#if>
    public ${column.javaType} get${column.propName}(){
        return ${column.varName};
    }

    /**${column.columnCaption!''}*/
    public void set${column.propName}(${column.javaType} value){
        this.${column.varName} = value;
    }
    <#if "QNumber" == column.javaType>
    /**${column.columnCaption!''}*/
    public void set${column.propName}Value(BigDecimal value){
        if(this.${column.varName} == null){ this.${column.varName} = new QNumber(value); }
        else { this.${column.varName}.setValue(value); }
    }
    </#if>
    <#if "QMoney" == column.javaType>
    /**${column.columnCaption!''}*/
    public void set${column.propName}Value(BigDecimal value){
        if(this.${column.varName} == null){ this.${column.varName} = new QMoney(value); }
        else { this.${column.varName}.setValue(value); }
    }
    </#if>
    <#if "QMoneyWanYuan" == column.javaType>
    /**${column.columnCaption!''}*/
    public void set${column.propName}Value(BigDecimal value){
        if(this.${column.varName} == null){ this.${column.varName} = new QMoneyWanYuan(value); }
        else { this.${column.varName}.setValue(value); }
    }
    </#if>
    <#if "QMoneyYuan" == column.javaType>
    /**${column.columnCaption!''}*/
    public void set${column.propName}Value(BigDecimal value){
        if(this.${column.varName} == null){ this.${column.varName} = new QMoneyYuan(value); }
        else { this.${column.varName}.setValue(value); }
    </#if>
    <#if "QPercent" == column.javaType>
    /**${column.columnCaption!''}*/
    public void set${column.propName}Value(BigDecimal value){
        if(this.${column.varName} == null){ this.${column.varName} = new QPercent(value); }
        else { this.${column.varName}.setValue(value); }
    }
    </#if>
</#list>

    public void parseFrom(Map<String, Object> row){
        RowMapper rowMapper = new RowMapper(row);
<#list columns as column>
        this.${column.varName} = rowMapper.get${column.javaType}("${column.columnName?upper_case}");
</#list>
    }

    @Override
    public boolean equals(Object obj) {
        if(obj == null)return false;
        if(id == null)return false;
        ${table.className} other = (${table.className})obj;
        return id.equals(other.id);
    }

    @Override
    public int hashCode() {
        if(id == null)return 0;
        return id.hashCode();
    }
}
